<template>
  <div style="padding-top: 10px; border: 1px solid rgba(242, 242, 242, 1)">
    <table
      style="border-color: #ccc"
      cellspacing="0"
      align="center"
      width="95%"
      border="1"
      bordercolor="#ccc"
      v-loading="loading"
    >
      <!-- <caption>
                          <font size="20" color="black"><h3 align="center">个人简历</h3></font>
                        </caption> -->
      <tr height="120">
        <th width="100" align="center">患者一般状况(20分)</th>
        <th width="700" colspan="2">
          <div class="r mb10 ml10">
            <span class="mr15">自理能力</span>
            <el-radio-group v-model="queryParams.selfCareAbilityScore">
              <el-radio
                v-for="(item, index) in radioList"
                :label="item.label"
                :key="index"
                @change="selfCareAbilityScore1(index)"
                >{{ item.value }}</el-radio
              >
            </el-radio-group>
          </div>
          <div class="r mb10 ml10">
            <span class="mr15">患者自述能力评价</span>
            <el-radio-group v-model="queryParams.expressionAbilityScore">
              <el-radio
                v-for="(item, index) in expressionAbilityScoreList"
                :label="item.label"
                :key="index"
                @change="expressionAbilityScore1(index)"
                >{{ item.value }}</el-radio
              >
            </el-radio-group>
          </div>
          <div class="r ml10">
            <span class="mr15">护理级别</span>
            <el-radio-group v-model="queryParams.careLevelScore">
              <el-radio
                v-for="(item, index) in careLevelScoreList"
                :label="item.label"
                :key="index"
                @change="careLevelScore1(index)"
                >{{ item.value }}</el-radio
              >
            </el-radio-group>
          </div>
        </th>
      </tr>
      <tr>
        <th width="100" align="center">患者生活方式(20分)</th>
        <th width="700" colspan="2" align="left">
          <div class="mb10 ml10" style="display: flex">
            <span class="" style="display: inline-block; width: 74px"
              >烟酒嗜好</span
            >
            <el-radio-group v-model="queryParams.smokeWineScore">
              <el-row
                :class="index !== 0 ? 'mt10' : ''"
                v-for="(item, index) in smokeWineScoreList"
                :key="index"
              >
                <el-col :span="24">
                  <el-radio
                    :label="item.label"
                    @change="smokeWineScore1(index)"
                    >{{ item.value }}</el-radio
                  >
                </el-col>
              </el-row>
            </el-radio-group>
          </div>
          <div class="mb10 ml10 mt20" style="display: flex">
            <span class="" style="display: inline-block; width: 74px"
              >饮食嗜好</span
            >
            <el-radio-group v-model="queryParams.eatScore">
              <el-row
                :class="index !== 0 ? 'mt10' : ''"
                v-for="(item, index) in eatScoreList"
                :key="index"
              >
                <el-col :span="24">
                  <el-radio :label="item.label" @change="eatScore1(index)">{{
                    item.value
                  }}</el-radio>
                </el-col>
              </el-row>
            </el-radio-group>
          </div>
          <div class="mb10 ml10 mt20" style="display: flex">
            <span class="" style="display: inline-block; width: 74px"
              >运动习惯</span
            >
            <el-radio-group v-model="queryParams.sportScore">
              <el-row
                :class="index !== 0 ? 'mt10' : ''"
                v-for="(item, index) in sportScoreList"
                :key="index"
              >
                <el-col :span="24">
                  <el-radio :label="item.label" @change="sportScore1(index)">{{
                    item.value
                  }}</el-radio>
                </el-col>
              </el-row>
            </el-radio-group>
          </div>
        </th>
      </tr>
      <tr>
        <th width="100" align="center">既往用药依从性(30分)</th>
        <th width="500" align="left">
          <div
            class="r"
            :class="index !== 0 ? 'mt10' : ''"
            v-for="(item, index) in eatPillsHobbyScoreList"
            :key="index"
          >
            {{ item.value }}
          </div>
        </th>
        <th
          width="200"
          align="left"
          style="line-height: 37px; padding-left: 20px"
        >
          <div>
            <el-radio-group
              v-model="queryParams.isForgetTakePillsSocre"
              @change="isForgetTakePillsSocre1"
            >
              <el-radio :label="0">是 (0分)</el-radio>
              <el-radio :label="6">否 (6分)</el-radio>
            </el-radio-group>
          </div>
          <div>
            <el-radio-group
              v-model="queryParams.isReduceStopPillsScore"
              @change="isReduceStopPillsScore1"
            >
              <el-radio :label="0">是 (0分)</el-radio>
              <el-radio :label="6">否 (6分)</el-radio>
            </el-radio-group>
          </div>
          <div>
            <el-radio-group
              v-model="queryParams.isForgetCarryPillsScore"
              @change="isForgetCarryPillsScore1"
            >
              <el-radio :label="0">是 (0分)</el-radio>
              <el-radio :label="6">否 (6分)</el-radio>
            </el-radio-group>
          </div>
          <div>
            <el-radio-group
              v-model="queryParams.isInsistScore"
              @change="isInsistScore1"
            >
              <el-radio :label="0">是 (0分)</el-radio>
              <el-radio :label="6">否 (6分)</el-radio>
            </el-radio-group>
          </div>
          <div>
            <el-radio-group
              v-model="queryParams.isTimeAmountScore"
              @change="isTimeAmountScore1"
            >
              <el-radio :label="0">是 (0分)</el-radio>
              <el-radio :label="6">否 (6分)</el-radio>
            </el-radio-group>
          </div>
        </th>
      </tr>
      <tr height="300">
        <th width="100" align="center">一般医药知识(30分)</th>
        <th
          width="700"
          colspan="2"
          align="left"
          style="padding: 20px 10px 0px 0px"
        >
          <div class="mb10 ml10" style="display: flex">
            <span style="display: inline-block; width: 130px"
              >对所患疾病了解程度</span
            >
            <el-radio-group v-model="queryParams.illnessKnowScore">
              <el-row
                :class="index !== 0 ? 'mt10' : ''"
                v-for="(item, index) in illnessKnowScoreList"
                :key="index"
              >
                <el-col :span="24">
                  <el-radio
                    :label="item.label"
                    @change="illnessKnowScore1(index)"
                    >{{ item.value }}</el-radio
                  >
                </el-col>
              </el-row>
            </el-radio-group>
          </div>
          <div class="mb10 ml10 mt20" style="display: flex">
            <span style="display: inline-block; width: 130px"
              >药物用法用量</span
            >
            <el-radio-group v-model="queryParams.pillsAmountScore">
              <el-row
                :class="index !== 0 ? 'mt10' : ''"
                v-for="(item, index) in pillsAmountScoreList"
                :key="index"
              >
                <el-col :span="24">
                  <el-radio
                    :label="item.label"
                    @change="pillsAmountScore1(index)"
                    >{{ item.value }}</el-radio
                  >
                </el-col>
              </el-row>
            </el-radio-group>
          </div>
          <div class="mb10 ml10 mt20" style="display: flex">
            <span style="display: inline-block; width: 130px"
              >药物不良反应</span
            >
            <el-radio-group v-model="queryParams.pillsBadScore">
              <el-row
                :class="index !== 0 ? 'mt10' : ''"
                v-for="(item, index) in pillsBadScoreList"
                :key="index"
              >
                <el-col :span="24">
                  <el-radio
                    :label="item.label"
                    @change="pillsBadScore1(index)"
                    >{{ item.value }}</el-radio
                  >
                </el-col>
              </el-row>
            </el-radio-group>
          </div>
          <div class="mb10 ml10 mt20" style="display: flex">
            <span style="display: inline-block; width: 130px"
              >药物相互作用</span
            >
            <el-radio-group v-model="queryParams.pillsEffectScore">
              <el-row
                :class="index !== 0 ? 'mt10' : ''"
                v-for="(item, index) in pillsEffectScoreList"
                :key="index"
              >
                <el-col :span="24">
                  <el-radio
                    :label="item.label"
                    @change="pillsEffectScore1(index)"
                    >{{ item.value }}</el-radio
                  >
                </el-col>
              </el-row>
            </el-radio-group>
          </div>
        </th>
      </tr>
      <tr height="100">
        <th width="100" align="center">评估结论</th>
        <th width="700" colspan="2" align="left">
          <div class="">
            <span>评估得分</span>
            <span
              class="value ml10"
              style="text-align: center; font-size: 16px"
              >{{ totalScore }}</span
            >
          </div>
          <div class="r mt10">
            <span>＞80为良好</span><span class="ml20">80-60为合格</span
            ><span class="ml20">＜60为不合格</span>
          </div>
        </th>
      </tr>
    </table>
    <el-button
      style="
        background-color: #1292b9;
        color: #fff;
        height: 36px;
        float: right;
        margin-top: 10px;
        margin-right: 20px;
      "
      @click="pharmacyAssess"
      v-hasPermi="['workstation:pharmacyAssess:add']"
      >保存</el-button
    >
  </div>
</template>

<script>
import { pharmacyAssess, medicalRecodeNo } from "@/api/workstation/baseInfo";
export default {
  name: "ruYuanPingGu",
  props: ["getYaoLiShouYeList"],
  data() {
    return {
      loading: true,
      radioList: [
        { label: 7, value: "完全自理 (7分)" },
        { label: 4, value: "部分依赖 (4分)" },
        { label: 0, value: "完全依赖 (进食、穿衣、淋浴、入厕) (0分)" },
      ],
      expressionAbilityScoreList: [
        { label: 7, value: "清晰 (7分)" },
        { label: 5, value: "基本清晰 (5分)" },
        { label: 3, value: "他人代诉 (3分)" },
        { label: 0, value: "不清晰且无他人代诉 (0分)" },
      ],
      careLevelScoreList: [
        { label: 0, value: "特级 (0分)" },
        { label: 2, value: "一级 (2分)" },
        { label: 4, value: "二级 (4分)" },
        { label: 6, value: "三级 (6分)" },
      ],
      smokeWineScoreList: [
        { label: 7, value: "不吸烟也不饮酒 (7分)" },
        {
          label: 5,
          value: "少量吸烟或饮酒 (5分) (每日吸烟＜10支或饮酒＜20g)",
        },
        {
          label: 3,
          value: "大量吸烟或饮酒 (3分) (每日吸烟10-20支或饮酒量为20-40g)",
        },
        {
          label: 0,
          value: "大量吸烟或过度酗酒 (0分) (每日吸烟＞20支或饮酒量＞40g)",
        },
      ],
      eatScoreList: [
        { label: 7, value: "无嗜糖、嗜油 (7分)" },
        {
          label: 5,
          value: "轻度嗜糖、嗜油 (5分) (每周3-5次高糖饮食或油腻饮食)",
        },
        {
          label: 3,
          value: "中度嗜糖、嗜油 (3分) (每日1次高糖饮食或油腻饮食)",
        },
        {
          label: 0,
          value: "重度嗜糖、嗜油 (0分) (每日2次以上高糖饮食或油腻饮食)",
        },
      ],
      sportScoreList: [
        { label: 6, value: "每周有氧运动≥3次 (6分)" },
        { label: 4, value: "每周有氧运动1-2次 (4分)" },
        { label: 2, value: "每月有氧运动1-2次 (2分)" },
        { label: 0, value: "每月有氧运动＜1次 (0分)" },
      ],
      eatPillsHobbyScoreList: [
        { label: 7, value: " ①在过去的2周内，是否有一天或几天您忘记服药？" },
        {
          label: 4,
          value:
            "②治疗期间，当您觉得症状减轻、加重或出现其他症状时，您是否未告知医生而自行减少药量或停止服药？",
        },
        {
          label: 0,
          value: "③当您外出旅行或长时间离家时，您是否有时忘记随身携带药物？",
        },
        { label: 4, value: "④您是否觉得要坚持治疗计划有困难？" },
        { label: 0, value: "⑤您觉得要记住按时服药很难吗？" },
      ],
      illnessKnowScoreList: [
        { label: 10, value: "能描述自身所患所有疾病 (10分)" },
        { label: 5, value: "能描述自身所患部分疾病 (5分)" },
        { label: 0, value: "完全不清楚自己所患疾病 (0分)" },
      ],
      pillsAmountScoreList: [
        { label: 10, value: "了解现服用所有药物的用法用量 (10分)" },
        { label: 5, value: "了解现服用部分药物的用法用量 (5分)" },
        { label: 0, value: "完全不了解现服用所有药物的用法用量 (0分)" },
      ],
      pillsBadScoreList: [
        { label: 5, value: "了解现服用所有药物的潜在不良反应 (5分)" },
        { label: 3, value: "了解现服用部分药物的潜在不良反应 (3分)" },
        { label: 0, value: "完全不了解现服用所有药物的潜在不良反应 (0分)" },
      ],
      pillsEffectScoreList: [
        { label: 5, value: "了解现服用所有药物的药物相互作用 (5分)" },
        { label: 3, value: "了解现服用部分药物的药物相互作用 (3分)" },
        { label: 0, value: "完全不了解现服用所有药物的药物相互作用 (0分)" },
      ],
      queryParams: {
        selfCareAbilityScore: "", // 自理能力分值
        selfCareAbilityLabel: "", // 自理能力标签
        expressionAbilityLabel: "", // 患者自述能力评价标签
        expressionAbilityScore: "", // 患者自述能力评价分值
        careLevelLabel: "", // 护理级别标签
        careLevelScore: "", // 护理级别分值
        generalConditionScore: "", // 患者一般状况总分值
        smokeWineLabel: "", // 烟酒嗜好标签
        smokeWineScore: "", // 烟酒嗜好分值
        eatLabel: "", // 饮食嗜好标签
        eatScore: "", // 饮食嗜好分值
        sportLabel: "", // 运动习惯标签
        sportScore: "", // 运动习惯分值
        liveStyleScore: "", // 患者生活方式总分值
        isForgetTakePillsLabel: "", // 是否忘记服药标签
        isForgetTakePillsSocre: "", // 是否忘记服药分值
        isReduceStopPillsLabel: "", // 是否减少或停止服药标签
        isReduceStopPillsScore: "", // 是否减少或停止服药分值
        isForgetCarryPillsLabel: "", // 是否忘记随身携带药物标签
        isForgetCarryPillsScore: "", // 是否忘记随身携带药物分值
        isInsistLabel: "", // 坚持治疗计划是否有困难标签
        isInsistScore: "", // 坚持治疗计划是否有困难分值
        isTimeAmountLabel: "", // 记住按时按量服药是否困难标签
        isTimeAmountScore: "", // 记住按时按量服药是否困难分值
        eatPillsHobbyScore: "", // 既往用药依从性总分值
        illnessKnowLabel: "", // 对所患疾病了解程度标签
        illnessKnowScore: "", // 对所患疾病了解程度分值
        pillsAmountLabel: "", // 药物用法用量标签
        pillsAmountScore: "", // 药物用法用量分值
        pillsBadLabel: "", // 潜在不良反应标签
        pillsBadScore: "", // 潜在不良反应分值
        pillsEffectLabel: "", // 药物相互作用标签
        pillsEffectScore: "", // 药物相互作用分值
        generalPillsScore: "", // 一般医药知识总分值
        totalScore: 0, // 入院药学评估总分值
        medicalRecordNo: "", // 病历号
        id: "", // 患者ID
      },
    };
  },
  created() {
    this.queryParams.medicalRecordNo = this.$route.query.medicalRecordNo;
    // this.queryParams.id = this.$route.query.id;
    //  先获取是否评估过
    medicalRecodeNo(this.queryParams.medicalRecordNo)
      .then((res) => {
        // this.loading = true;
        if (res.data != null) {
          this.queryParams = res.data;
          this.loading = false;
          console.log(this.queryParams);
        }
      })
      .finally(() => {
        this.loading = false;
      });
  },
  computed: {
    // 患者一般状况总分值
    generalConditionScore() {
      return (
        Number(this.queryParams.selfCareAbilityScore) +
          Number(this.queryParams.expressionAbilityScore) +
          Number(this.queryParams.careLevelScore) || 0
      );
    },
    // 患者生活方式总分值
    liveStyleScore() {
      return (
        Number(this.queryParams.smokeWineScore) +
          Number(this.queryParams.eatScore) +
          Number(this.queryParams.sportScore) || 0
      );
    },
    // 既往用药依从性总分值
    eatPillsHobbyScore() {
      return (
        Number(this.queryParams.isForgetTakePillsSocre) +
          Number(this.queryParams.isReduceStopPillsScore) +
          Number(this.queryParams.isForgetCarryPillsScore) +
          Number(this.queryParams.isInsistScore) +
          Number(this.queryParams.isTimeAmountScore) || 0
      );
    },
    // 一般医药知识总分值
    generalPillsScore() {
      return (
        Number(this.queryParams.illnessKnowScore) +
          Number(this.queryParams.pillsAmountScore) +
          Number(this.queryParams.pillsBadScore) +
          Number(this.queryParams.pillsEffectScore) || 0
      );
    },
    // 评估总分
    totalScore() {
      return (
        Number(this.queryParams.selfCareAbilityScore) +
          Number(this.queryParams.expressionAbilityScore) +
          Number(this.queryParams.careLevelScore) +
          Number(this.queryParams.smokeWineScore) +
          Number(this.queryParams.eatScore) +
          Number(this.queryParams.sportScore) +
          Number(this.queryParams.isForgetTakePillsSocre) +
          Number(this.queryParams.isReduceStopPillsScore) +
          Number(this.queryParams.isForgetCarryPillsScore) +
          Number(this.queryParams.isInsistScore) +
          Number(this.queryParams.isTimeAmountScore) +
          Number(this.queryParams.illnessKnowScore) +
          Number(this.queryParams.pillsAmountScore) +
          Number(this.queryParams.pillsBadScore) +
          Number(this.queryParams.pillsEffectScore) || 0
      );
    },
  },
  // watch: {
  //   totalScore(newVal, oldVal) {
  //     console.log(newVal, oldVal);
  //   },
  // },
  methods: {
    // 保存入院药学评估
    async pharmacyAssess() {
      console.log(this.queryParams);
      if (
        !this.queryParams.selfCareAbilityLabel ||
        !this.queryParams.expressionAbilityLabel ||
        !this.queryParams.careLevelLabel ||
        !this.queryParams.smokeWineLabel ||
        !this.queryParams.eatLabel ||
        !this.queryParams.sportLabel ||
        !this.queryParams.isForgetTakePillsLabel ||
        !this.queryParams.isReduceStopPillsLabel ||
        !this.queryParams.isForgetCarryPillsLabel ||
        !this.queryParams.isInsistLabel ||
        !this.queryParams.isTimeAmountLabel ||
        !this.queryParams.illnessKnowLabel ||
        !this.queryParams.pillsAmountLabel ||
        !this.queryParams.pillsBadLabel ||
        !this.queryParams.pillsEffectLabel
      ) {
        this.$message({
          message: "请先填写完整后保存！",
          showClose: true,
        });
        return;
      }
      this.queryParams.generalConditionScore = this.generalConditionScore + "";
      this.queryParams.liveStyleScore = this.liveStyleScore + "";
      this.queryParams.eatPillsHobbyScore = this.eatPillsHobbyScore + "";
      this.queryParams.generalPillsScore = this.generalPillsScore + "";
      this.queryParams.totalScore = this.totalScore + "";
      const res = await pharmacyAssess(this.queryParams);
      if (res.code == 200) {
        this.$message({
          type: "success",
          message: res.msg,
        });
        this.getYaoLiShouYeList();
      } else {
        this.$message({
          type: "error",
          message: res.msg,
        });
      }
    },
    // 自理能力标签
    selfCareAbilityScore1(index) {
      this.queryParams.selfCareAbilityLabel = this.radioList[index].value;
      // console.log(this.queryParams.selfCareAbilityLabel);
    },
    // 患者自述能力评价标签
    expressionAbilityScore1(index) {
      this.queryParams.expressionAbilityLabel =
        this.expressionAbilityScoreList[index].value;
    },
    // 护理级别标签
    careLevelScore1(index) {
      this.queryParams.careLevelLabel = this.careLevelScoreList[index].value;
      // console.log(this.queryParams);
    },
    // 烟酒嗜好标签
    smokeWineScore1(index) {
      this.queryParams.smokeWineLabel = this.smokeWineScoreList[index].value;
      // console.log(this.queryParams);
    },
    // 饮食嗜好标签
    eatScore1(index) {
      this.queryParams.eatLabel = this.eatScoreList[index].value;
      // console.log(this.queryParams);
    },
    // 运动习惯标签
    sportScore1(index) {
      this.queryParams.sportLabel = this.sportScoreList[index].value;
      // console.log(this.queryParams);
    },
    // 是否忘记服药标签
    isForgetTakePillsSocre1() {
      this.queryParams.isForgetTakePillsLabel =
        this.eatPillsHobbyScoreList[0].value;
    },
    // 是否减少或停止服药标签
    isReduceStopPillsScore1() {
      this.queryParams.isReduceStopPillsLabel =
        this.eatPillsHobbyScoreList[1].value;
    },
    // 是否忘记随身携带药物标签
    isForgetCarryPillsScore1() {
      this.queryParams.isForgetCarryPillsLabel =
        this.eatPillsHobbyScoreList[2].value;
    },
    // 坚持治疗计划是否有困难标签
    isInsistScore1() {
      this.queryParams.isInsistLabel = this.eatPillsHobbyScoreList[3].value;
    },
    // 记住按时按量服药是否困难标签
    isTimeAmountScore1() {
      this.queryParams.isTimeAmountLabel = this.eatPillsHobbyScoreList[4].value;
    },
    // 对所患疾病了解程度标签
    illnessKnowScore1(index) {
      this.queryParams.illnessKnowLabel =
        this.illnessKnowScoreList[index].value;
      // console.log(this.queryParams);
    },
    // 药物用法用量标签
    pillsAmountScore1(index) {
      this.queryParams.pillsAmountLabel =
        this.pillsAmountScoreList[index].value;
      // console.log(this.queryParams);
    },
    // 潜在不良反应标签
    pillsBadScore1(index) {
      this.queryParams.pillsBadLabel = this.pillsBadScoreList[index].value;
      // console.log(this.queryParams);
    },
    // 药物相互作用标签
    pillsEffectScore1(index) {
      this.queryParams.pillsEffectLabel =
        this.pillsEffectScoreList[index].value;
      // console.log(this.queryParams);
    },
    // 左侧菜单激活面板
    handleChange(val) {
      // medicalRecodeNo
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-radio__label {
  padding-left: 7px;
}

::v-deep .el-radio {
  margin-right: 10px;
}

table > tr > th > div {
  // width: 100%;
  font-weight: normal;
}

table > tr > th {
  padding: 20px 10px 10px 10px;
}

.value {
  display: inline-block;
  min-width: 100px;
  border-bottom: 1px solid #000;
}

.headTxt {
  font-size: 18px;
  font-weight: 900;
  margin-left: 19px;
}
table {
  border-collapse: collapse !important;
  border-color: #ccc !important;
}
</style>
